#include <stdio.h>
#include <string.h>

int main()
{
    //r --》 如果文件不存在，则报错
    FILE* fp = fopen("./linux84", "w+");
    if(!fp)
    {
        perror("fopen");
        printf("open file failed\n");
        return -1;
    }
    printf("open file success\n");

    const char* str = "linux so easy";
    ssize_t ret = fwrite(str, 1, strlen(str), fp);
    printf("write block count is %d\n", ret);

    fseek(fp, 1, SEEK_SET);

    char buf[1024] = {0};
    //将块的大小设置成为1， 是公司当中常用的方式
    //但是我们一定要理解参数的含义
    ret = fread(buf, 1, 4, fp);
    printf("ret=%d, buf=%s\n", ret, buf);

    fclose(fp);
    return 0;
}
